package com.crack.spansframe;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.style.LineBackgroundSpan;

/**
 * Created by archermind on 16-4-19.
 */
public class LineSpan implements LineBackgroundSpan {
    int color;

    public LineSpan() {
        this(Color.BLACK);
    }

    public LineSpan(int color) {
        this.color = color;
    }

    @Override
    public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline, int bottom, CharSequence text, int start, int end, int lnum) {
        float y = (top + bottom) * 1.0f / 2;
        int oldColor = p.getColor();
        p.setColor(this.color);
        c.drawLine(left, y - 1, right, y + 1, p);
        p.setColor(oldColor);
    }
}
